﻿#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="TweenPosition.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2008, 2009, 2010, 2011
//       Roland Rosenkranz (Glatzemann@email.de)
// </copyright>
// <license>
//   This file is part of starLiGHT.Particles.
//
//   starLiGHT.Particles is free software: you can redistribute it and/or modify
//   it under the terms of the GNU Lesser General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   starLiGHT.Particles is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Lesser General Public License for more details.
//
//   You should have received a copy of the GNU Lesser General Public License
//   along with starLiGHT.Particles. If not, see http://www.gnu.org/licenses/.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.Particles are available on request.
// </license>
// <original_license>
//  * FLINT PARTICLE SYSTEM
//  * .....................
//  * 
//  * Author: Richard Lord
//  * Copyright (c) Richard Lord 2008-2009
//  * http://flintparticles.org
//  * 
//  * 
//  * Licence Agreement
//  * 
//  * Permission is hereby granted, free of charge, to any person obtaining a copy
//  * of this software and associated documentation files (the "Software"), to deal
//  * in the Software without restriction, including without limitation the rights
//  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  * copies of the Software, and to permit persons to whom the Software is
//  * furnished to do so, subject to the following conditions:
//  * 
//  * The above copyright notice and this permission notice shall be included in
//  * all copies or substantial portions of the Software.
//  * 
//  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  * THE SOFTWARE.
// </original_license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev::                       $:  Revision of last commit *
// * $Author::                    $:  Author of last commit   *
// * $Date::                      $:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.ParticleSystem.Modifier.twoD
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Text;
    using starLiGHT.ParticleSystem.Common;
    using starLiGHT.ParticleSystem.twoD;

    #endregion

    /// <summary>
    /// The TweenPosition modifier adjusts the particle's position between two 
    /// locations as it ages. The position is relative to the particle's energy, 
    /// which changes as the particle ages in accordance with the energy easing 
    /// function used. This modifier should be used in conjunction with the age 
    /// modifier.
    /// </summary>
    public class TweenPosition : Modifier2DBase
    {
        private float _diffX;
        private float _endX;
        private float _diffY;
        private float _endY;

        public TweenPosition()
            : this(0, 0, 0, 0)
        {
        }

        public TweenPosition(float startX, float startY, float endX, float endY)
        {
            StartX = startX;
            EndX = endX;
            StartY = startY;
            EndY = endY;
        }

        public float StartX
        {
            get { return this._endX + this._diffX; }
            set { this._diffX = value - this._endX; }
        }

        public float EndX
        {
            get { return this._endX; }
            set { this._diffX = this._endX + this._diffX - value; this._endX = value; }
        }

        public float StartY
        {
            get { return this._endY + this._diffY; }
            set { this._diffY = value - this._endY; }
        }

        public float EndY
        {
            get { return this._endY; }
            set { this._diffY = this._endY + this._diffY - value; this._endY = value; }
        }

        public override void Update(Emitter2D emitter, Particle2D particle, float time)
        {
            particle.position.X = _endX + _diffX * particle.energy;
            particle.position.Y = _endY + _diffY * particle.energy;
        }
    }
}
